package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Log() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println("log start")
		//c.Next()
		fmt.Println("log end")
		// 直接退出，后面的就不执行了
		c.Abort()
	}
}

func RequestID() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println("requestid start")
		c.Next()
		fmt.Println("requestid end")
	}
}

func main() {
	r := gin.Default()
	// 中间件 USE 调用有顺序
	r.Use(RequestID(), Log())
	r.GET("/", func(context *gin.Context) {
		fmt.Println("app running")
		context.JSON(http.StatusOK, gin.H{
			"msg": "hello world",
		})
	})
	r.Run(":8000")
}
